<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once ('base.php');

class Admin extends Base {
	
	public function __construct()	{
		parent::__construct();
	}
	
	public function products() {
		$this->load->model('Product_model');
		$this->baseData['products'] = $this->Product_model->listProducts();
		$this->templateData['contentLeft'] = $this->load->view('adminproducts',$this->baseData,true);
		$this->templateData['contentRight'] = '';
		$this->templateData['header'] = $this->load->view('adminheader', $this->baseData, true);
		$this->load->view('index', $this->templateData);
	}
	
	public function userslist() {
		$this->load->model('User_model');
		$this->baseData['users'] = $this->User_model->listUsers();
		$this->templateData['contentLeft'] = $this->load->view('userslist',$this->baseData,true);
		$this->templateData['contentRight'] = '';
		$this->templateData['header'] = $this->load->view('adminheader', $this->baseData, true);
		$this->load->view('index', $this->templateData);
	}
	
	public function changestatus() {
		$id = $this->input->post('id');
		$status = $this->input->post('status');
		
		$this->load->model('Order_model');
		$this->Order_model->editStatus($id, $status);
	}
	
	public function index() {
		//display
		$this->load->model('Order_model');
		$this->baseData['orders'] = $this->Order_model->listOrders();
		$this->templateData['contentLeft'] = $this->load->view('admin',$this->baseData,true);
		$this->templateData['contentRight'] = '';
		$this->templateData['header'] = $this->load->view('adminheader', $this->baseData, true);
		$this->load->view('index', $this->templateData);
	}
	
	public function order($id) {
		$this->load->model('Order_model');
		$order = $this->Order_model->getDetail($id);
		$order = $order[0];
		
		if ($order->payment == 1)	{
			$order->payment = "Trực tiếp";
		}
		if ($order->discount != 0 && $order->discount != null)
			$order->price = $order->discount;
		$this->baseData['order'] = $order;
		$this->templateData['contentLeft'] = $this->load->view('orderadmin',$this->baseData,true);
		$this->templateData['contentRight'] = '';
		$this->templateData['header'] = $this->load->view('adminheader', $this->baseData, true);
		$this->load->view('index', $this->templateData);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */